package com.qf.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.service.ElasticsearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/*** @author xl
 * @version V1.0
 * @Project sms_platform
 * @Package com.qf.controller
 * @Description: ${TODO}
 *@Date 2022/8/29 16:36
 *         搜索查看日志和日志统计报表接口
 */
@RestController
public class SearchController {

    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private ElasticsearchService elasticsearchService;

    /**
     *      根据条件查询日志总条数
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/search/searchcount", method = RequestMethod.POST)
    public Long searchLogCount(@RequestParam("params") String params) throws IOException {
        //1.将params手动反序列化为Map对象
        Map parameter = objectMapper.readValue(params, Map.class);
        //2.查询数据总条数
        Long count=elasticsearchService.searchLogCount(parameter);
        return count;
    }

    /**
     *      查询搜索日志列表
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/search/search",method = RequestMethod.POST)
    public List<Map> searchLog(@RequestParam("params") String params) throws IOException{

        //1.手动反序列化为Map对象
        Map parameter=objectMapper.readValue(params,Map.class );
        //2.查询数据日志信息
        List<Map> data=elasticsearchService.searchLog(parameter);
        return data;
    }


    /**
     *      统计报表查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/search/statStatus",method = RequestMethod.POST)
    public Map<String,Long> statSendStatus(@RequestParam("params") String params) throws IOException{

        //1.手动反序列化为Map对象
        Map parameter=objectMapper.readValue(params,Map.class );
        //2.查询状态
        Map<String,Long> data=elasticsearchService.statSendStatus(parameter);
        return data;
    }

}
